package org.jeecg.modules.jxc.statistical.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.jxc.statistical.entity.JxcPurchaseList;
import org.jeecg.modules.jxc.statistical.service.IJxcPurchaseListService;

import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;

 /**
 * @Description: jxc_purchase_list
 * @Author: jeecg-boot
 * @Date:   2021-12-20
 * @Version: V1.0
 */
@Api(tags="jxc_purchase_list")
@RestController
@Slf4j
@SuppressWarnings("all")
public class JxcPurchaseListController extends JeecgController<JxcPurchaseList, IJxcPurchaseListService> {
	@Autowired
	private IJxcPurchaseListService jxcPurchaseListService;

	/**
	* @description:  获取供应商进货退货单列表
	* @param begin  时间范围
	* @param end
	* @param state  是否付（退）款
	* @param key    供应商名称
	* @return org.jeecg.common.api.vo.Result<?>
	* @exception
	*/
	@GetMapping(value = "/purchaseListGoods/list")
	public Result<?> queryPageList(String begin, String end, String state, String key) {
		List<Map<String,Object>> mapList = jxcPurchaseListService.findSupplierJHAndTHTotalList(begin,end,state,key);
		HashMap<String, Object> records = new HashMap<>();
		records.put("records",mapList);
		return Result.ok(records);
	}

	/**
	* @description:  根据单号（number）找到对应的 id  根据id找到对应单号具体商品表
	* @param selectedNumber  判别number  判断是进货单还是退货单
	* @return org.jeecg.common.api.vo.Result<?>
	* @exception
	*/
	@GetMapping("/purchaseListGoods/{selectedNumber}")
	public Result<?> goodsListDetail(@PathVariable("selectedNumber") String selectedNumber){
		List<Map<String,Object>> resultMap =jxcPurchaseListService.findGoodsListDetail(selectedNumber);
		return Result.ok(resultMap);
	}

	/**
	* @description: 供应商进货单支付结算
	* @param receive
	* @return org.jeecg.common.api.vo.Result<?>
	* @exception
	*/
	@PostMapping("/purchaseListGoods/updateState")
	public Map<String, Object> payEnd(@RequestBody Map<String,Integer> receive){
		Integer purchaseListId = receive.get("purchaseListId");
		Boolean tag = jxcPurchaseListService.putJHPayState(purchaseListId);
		Map<String, Object> returnMap = new HashMap<>();
		if (tag){
			returnMap.put("code",100);
			returnMap.put("msg","请求成功");
			returnMap.put("info",null);
		}else {
			returnMap.put("code",500);
			returnMap.put("msg","请求错误");
			returnMap.put("info",null);
		}
		return returnMap;
	}

	/**
	* @description:  销售单支付结算
	* @param receive
	* @return java.util.Map<java.lang.String,java.lang.Object>
	* @exception
	*/
	@PostMapping("/saleListGoods/updateState")
	public Map<String, Object> payXSEnd(@RequestBody Map<String,Integer> receive){
		Integer saleListId = receive.get("saleListId");
		Boolean tag = jxcPurchaseListService.putXSPayState(saleListId);
		Map<String, Object> returnMap = new HashMap<>();
		if (tag){
		 returnMap.put("code",100);
		 returnMap.put("msg","请求成功");
		 returnMap.put("info",null);
		}else {
		 returnMap.put("code",500);
		 returnMap.put("msg","请求错误");
		 returnMap.put("info",null);
		}
		return returnMap;
	}

	/**
	* @description: 进货统计
	* @param sTime
	* @param eTime
	* @param goodsTypeId
	* @param codeOrName
	* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	* @exception
	*/
	@PostMapping("/purchaseListGoods/count")
	public List<Map<String, Object>> goodsJHTotal(String sTime, String eTime, Integer goodsTypeId, String codeOrName) {
		List<Map<String, Object>> resultMap = jxcPurchaseListService.findJHTotal(sTime, eTime, goodsTypeId, codeOrName);
		return resultMap;
	}

	/**
	* @description: 退货统计
    * @param sTime
	* @param eTime
	* @param goodsTypeId
	* @param codeOrName
	* @return java.util.List<java.util.Map               <               java.lang.String               ,               java.lang.Object>>
	* @throws
	*/
	@PostMapping("/returnListGoods/count")
	public List<Map<String, Object>> goodsTHTotal(String sTime, String eTime, Integer goodsTypeId, String codeOrName) {
		List<Map<String, Object>> resultMap = jxcPurchaseListService.findTHTotal(sTime, eTime, goodsTypeId, codeOrName);
		return resultMap;
	}

	/**
	* @description:  商品销售统计
	* @param sTime
	* @param eTime
	* @param goodsTypeId
	* @param codeOrName
	* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	* @exception
	*/
	@PostMapping("/saleListGoods/count")
	public List<Map<String, Object>> goodsXSTotal(String sTime, String eTime, Integer goodsTypeId, String codeOrName) {
        List<Map<String, Object>> resultMap = jxcPurchaseListService.findXSTotal(sTime, eTime, goodsTypeId, codeOrName);
        return resultMap;
    }

    /**
    * @description:  客户退货统计（可根据 商品类别、商品编码或名称 条件查询）
    * @param sTime
    * @param eTime
    * @param goodsTypeId
    * @param codeOrName
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @exception
    */
    @PostMapping("/customerReturnListGoods/count")
    public List<Map<String,Object>> goodsXTTotal(String sTime, String eTime, Integer goodsTypeId, String codeOrName) {
		List<Map<String, Object>> resultMap = jxcPurchaseListService.findXTTotal(sTime,eTime,goodsTypeId,codeOrName);
		return resultMap;
	}

	/**
	* @description:  每日销售 成本 利润统计
	* @param sTime
	* @param eTime
	* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	* @exception
	*/
	@PostMapping("/saleListGoods/getSaleDataByDay")
	public List<Map<String,Object>> getDayProfitList(String sTime, String eTime){
        List<Map<String, Object>> resultMap = jxcPurchaseListService.findDayProfitList(sTime,eTime);
        return resultMap;
    }

    /**
    * @description: 每月销售 成本 利润统计
    * @param sTime  前端格式 xxxx-xx    (没有天数，后端自己拼接)
    * @param eTime
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @exception
    */
    @PostMapping("/saleListGoods/getSaleDataByMonth")
    public List<Map<String,Object>> getMonthProfitList(String sTime, String eTime){
        List<Map<String, Object>> resultMap = jxcPurchaseListService.findMonthProfitList(sTime,eTime);
        return resultMap;
    }
}
